﻿/*
#------------------------------------------------------------------------------
#-- Program Name:	[dbo].[spMSX_manual_update_server]
#-- Purpose:		Manually updates a server in the list of servers to inventory
#--	Last Update:	04/06/2016
#--					For a complete history - please review comments in Version
#--					Control.
#------------------------------------------------------------------------------
*/
CREATE PROCEDURE [dbo].[spMSX_manual_update_server]
(
	@ssd_server_name				varchar(60),
	@ssd_deploy_msx_backup			bit,
	@ssd_deploy_msx_index			bit,
	@ssd_is_mission_critical		bit,
	@ssd_cluster_name				varchar(20)		= NULL
)
AS

IF NOT EXISTS (
			SELECT	TOP 1 [ssd_server_name]
			FROM	[dbo].[tblMSX_server_discovery] (NOLOCK)
			WHERE	[ssd_is_disabled] = 0
					AND [ssd_server_name] = @ssd_server_name
		  )
  BEGIN
	RAISERROR('This server has not been added and cannot be updated.', 16, 1)
	RETURN -1
  END

UPDATE	[dbo].[tblMSX_server_discovery]
SET		ssd_deploy_msx_backup = @ssd_deploy_msx_backup,
		ssd_deploy_msx_index = @ssd_deploy_msx_index,
		ssd_last_update = GETDATE(),
		ssd_is_mission_critical = @ssd_is_mission_critical,
		ssd_cluster_name = @ssd_cluster_name
WHERE	ssd_server_name = @ssd_server_name
		AND NOT (
			ssd_deploy_msx_backup = @ssd_deploy_msx_backup
			AND ssd_deploy_msx_index = @ssd_deploy_msx_index
			AND ssd_is_mission_critical = @ssd_is_mission_critical
			AND ISNULL(ssd_cluster_name, SPACE(0)) = ISNULL(@ssd_cluster_name, SPACE(0))
		)
